package com.team5.mapper;

import com.team5.entity.CashFlow;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
@Mapper
public interface CashFlowMapper {
    @Select("select * from \"SCOTT\".HONGKONGFUND where id=#{id}")//SCOTT改为自己的数据库名
    CashFlow findById(Integer id);
    @Select("select * from \"SCOTT\".HONGKONGFUND")
    CashFlow[] findAll();
    //2024/5/22 hjy
    @Select("select * from \"SCOTT\".HONGKONGFUND where name=#{name}")
    CashFlow findByName(String name);
    @Delete("delete from \"SCOTT\".HONGKONGFUND where id=#{id}")
    int deleteById(Integer id);
    @Delete("delete from \"SCOTT\".HONGKONGFUND where name=#{name}")
    int deleteByName(String name);
    @Delete("delete from \"SCOTT\".HONGKONGFUND")
    int deleteAll();
    @Insert("insert into \"SCOTT\".HONGKONGFUND (id, name, money, maxnum, flow) " +
            "values (#{id}, #{name}, #{money}, #{maxnum}, #{flow})")
    @SelectKey(statement = "SELECT seq_ganggu.NEXTVAL FROM DUAL", keyProperty = "id", before = true, resultType = int.class)
    int insert(CashFlow cashFlow);

    @Update("update \"SCOTT\".HONGKONGFUND set " +
            "money=#{cflow.money}, maxnum=#{cflow.maxnum}, flow=#{cflow.flow} where name=#{cflow.name}")
    int updateByName(@Param("cflow")CashFlow cflow);
}
